function setActiveStyleSheet(title) {
    myLog("setActiveStyleSheet:" + title)
    var i, a;
    for (i = 0; (document.getElementsByTagName("link")[i]); i++) {
        a = document.getElementsByTagName("link")[i];
        myLog("link[" + i + "]:" + a.getAttribute("rel"));
        if (a.getAttribute("rel").indexOf("style") !== -1 && a.getAttribute("title")) {
            a.disabled = true;
            if (a.getAttribute("title") === title) {
                a.disabled = false;
            }
        }
    }
}

function getActiveStyleSheet() {
    var i, a;
    for (i = 0; (document.getElementsByTagName("link")[i]); i++) {
        a = document.getElementsByTagName("link")[i];
        if (a.getAttribute("rel").indexOf("style") !== -1 && a.getAttribute("title") && !a.disabled)
            return a.getAttribute("title");
    }
    return null;
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else
        expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    myLog("document.cookie:" + document.cookie);
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) === ' ')
            c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) === 0)
            return c.substring(nameEQ.length, c.length);
    }
    return null;
}

window.onload = function(e) {
    var cookie = readCookie("style");
    var title = (cookie && cookie !== "null") ? cookie : "main1";
    setActiveStyleSheet(title);
    //
    getInfo();
};



window.onunload = function(e) {
    var title = getActiveStyleSheet();
    createCookie("style", title, 365);
};

function myLog(msg) {
    if (hasConsoleLog()) {
        console.log(msg);
    }
}

function hasConsoleLog() {
    if (navigator.userAgent.match("Firefox")) {
        return true;
    } else if (navigator.userAgent.match("Chrome")) {
        return true;
    }
    return false;
}

function getInfo() {
    var s = "";
    s += " 網頁可見區域寬：" + document.body.clientWidth +"\r\n";
    s += " 網頁可見區域高：" + document.body.clientHeight+"\r\n";
    s += " 網頁可見區域寬：" + document.body.offsetWidth + " (包括邊線和捲軸的寬)"+"\r\n";
    s += " 網頁可見區域高：" + document.body.offsetHeight + " (包括邊線的寬)"+"\r\n";
    s += " 網頁正文全文寬：" + document.body.scrollWidth+"\r\n";
    s += " 網頁正文全文高：" + document.body.scrollHeight+"\r\n";
    s += " 網頁被卷去的高(ff)：" + document.body.scrollTop+"\r\n";
    s += " 網頁被卷去的高(ie)：" + document.documentElement.scrollTop+"\r\n";
    s += " 網頁被卷去的左：" + document.body.scrollLeft+"\r\n";
    s += " 網頁正文部分上：" + window.screenTop+"\r\n";
    s += " 網頁正文部分左：" + window.screenLeft+"\r\n";
    s += " 螢幕解析度的高：" + window.screen.height+"\r\n";
    s += " 螢幕解析度的寬：" + window.screen.width+"\r\n";
    s += " 螢幕可用工作區高度：" + window.screen.availHeight+"\r\n";
    s += " 螢幕可用工作區寬度：" + window.screen.availWidth+"\r\n";
    s += " 你的螢幕設置是 " + window.screen.colorDepth + " 位彩色"+"\r\n";
    s += " 你的螢幕設置 " + window.screen.deviceXDPI + " 像素/英寸"+"\r\n";
    //alert (s);
    myLog(s);
}